1   package com.iluwatar;
2   
3   /**
4    * Every instance of this class represents the Stub component in the
5    * Model-View-Presenter architectural pattern.
6    * 
7    * The stub implements the View interface and it is useful when we want the test
8    * the reaction to user events, such as mouse clicks.
9    * 
10   * Since we can not test the GUI directly, the MVP pattern provides this
11   * functionality through the View's dummy implementation, the Stub.
12   */
13  public class FileSelectorStub implements FileSelectorView {
14  
15  	/**
16  	 * Indicates whether or not the view is opened.
17  	 */
18  	private boolean opened;
19  
20  	/**
21  	 * The presenter Component.
22  	 */
23  	private FileSelectorPresenter presenter;
24  
25  	/**
26  	 * The current name of the file.
27  	 */
28  	private String name;
29  
30  	/**
31  	 * Indicates the number of messages that were "displayed" to the user.
32  	 */
33  	private int numOfMessageSent;
34  
35  	/**
36  	 * Indicates if the data of the file where displayed or not.
37  	 */
38  	private boolean dataDisplayed;
39  
40  	/**
41  	 * Constructor
42  	 */
43  	public FileSelectorStub() {
44  		this.opened = false;
45  		this.presenter = null;
46  		this.name = "";
47  		this.numOfMessageSent = 0;
48  		this.dataDisplayed = false;
49  	}
50  
51  	@Override
52  	public void open() {
53  		this.opened = true;
54  	}
55  
56  	@Override
57  	public void setPresenter(FileSelectorPresenter presenter) {
58  		this.presenter = presenter;
59  	}
60  
61  	@Override
62  	public boolean isOpened() {
63  		return this.opened;
64  	}
65  
66  	@Override
67  	public FileSelectorPresenter getPresenter() {
68  		return this.presenter;
69  	}
70  
71  	@Override
72  	public String getFileName() {
73  		return this.name;
74  	}
75  
76  	@Override
77  	public void setFileName(String name) {
78  		this.name = name;
79  	}
80  
81  	@Override
82  	public void showMessage(String message) {
83  		this.numOfMessageSent++;
84  	}
85  
86  	@Override
87  	public void close() {
88  		this.opened = false;
89  	}
90  
91  	@Override
92  	public void displayData(String data) {
93  		this.dataDisplayed = true;
94  	}
95  
96  	/**
97  	 * Returns the number of messages that were displayed to the user.
98  	 */
99  	public int getMessagesSent() {
100 		return this.numOfMessageSent;
101 	}
102 
103 	/**
104 	 * @return True if the data where displayed, false otherwise.
105 	 */
106 	public boolean dataDisplayed() {
107 		return this.dataDisplayed;
108 	}
109 }